﻿using System;
using System.Collections.Generic;

using EHSubmit.Model;

namespace EHSubmit.Logic.Analysis
{
    /// <summary>
    ///  
    /// </summary>
    public class ChartDataDigester
    {
        public ChartDataDigester()
        {

        }

        /// <summary>
        /// 饼图数据封装内部类
        /// </summary>
        public class PieChartModel
        {
            public PieChartModel() { }

            public PieChartModel(string category, int total) {
                this.category = category;
                this.total = total;
            }

            string category;

            public string Category
            {
                get { return category; }
                set { category = value; }
            }

            int total;

            public int Total
            {
                get { return total; }
                set { total = value; }
            }

        }

        /// <summary>
        /// 将某次作业全班分数按等级分类封装
        /// </summary>
        /// <param name="goalId"></param>
        /// <returns></returns>
        public IList<PieChartModel> GetPieChartData(int goalId)
        {
            // 获得该goal下所有已提交的作业
            IList<Homework> works = new HomeworkManager().ListByGoalId(goalId);
            // 将分类数据封装的集合
            IList<PieChartModel> models = new List<PieChartModel>();

            // 按分数分为四个等级
            PieChartModel level1 = new PieChartModel("90分以上",0);
            PieChartModel level2 = new PieChartModel("80至90分", 0);
            PieChartModel level3 = new PieChartModel("60至80分",0);
            PieChartModel level4 = new PieChartModel("60分以下",0);


            foreach (Homework w in works)
            {
                if (w.Scores > 90)
                {
                    level1.Total++;
                }
                else if(w.Scores > 80)
                {
                    level2.Total++;
                }
                else if (w.Scores > 60)
                {
                    level3.Total++;
                }
                else
                {
                    level4.Total++;
                }
            }

            models.Add(level1);
            models.Add(level2);
            models.Add(level3);
            models.Add(level4);

            return models;
        }
    }
}